package com.meida.module.bus.provider.handler;

import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.utils.ApiAssert;
import com.meida.module.bus.client.enums.BalanceLogTypeEnum;
import com.meida.module.pay.client.entity.PayRecharge;
import com.meida.module.pay.provider.handler.PayRechargeHandler;
import com.meida.module.pay.provider.service.PayBalanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 余额充值充值到绑定金
 */
@Component
public class ApplePayRechargeHandler implements PayRechargeHandler {

    @Autowired
    private PayBalanceService payBalanceService;

    @Override
    public Boolean balanceRecharge(Long userId, PayRecharge payRecharge) {
        if (FlymeUtils.isEmpty(payRecharge)) {
            ApiAssert.failure("内购配置为空");
        }
        BigDecimal cybermoney = payRecharge.getCybermoney();
        String title = "留币充值";
        String body = "充值到账成功" + cybermoney + "留币";
        Boolean result = payBalanceService.addBindAmount(userId, userId, cybermoney, BalanceLogTypeEnum.logType1.getValue(), title, body);
        return result;
    }
}
